import wx
import wx.aui
import wx.lib.ogl as ogl  
from pannello_ER import PannelloER
from pannello_ER import MyEvtHandler

class MyPanel4 ( wx.Panel ):
    
        def __init__( self, parent ):
            wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, style = wx.TAB_TRAVERSAL )
        
            agg_q = wx.Button(self, -1, 'agg. quadrato')  
            agg_c = wx.Button(self, -1, 'agg. cerchio')  
            canc = wx.Button(self, -1, 'cancella')  
            # ------ la parte importante:  
            # ogni canvas ha un diagramma, devono essere collegati tra loro,   
            # e si usano entrambi a seconda delle occasioni...  
            self.canvas = ogl.ShapeCanvas(self)  
            self.diag = ogl.Diagram()  
            self.diag.SetCanvas(self.canvas)  
            self.canvas.SetDiagram(self.diag)  
            # -------  
            s = wx.BoxSizer(wx.VERTICAL)  
            for b in (agg_q, agg_c, canc):  
                s.Add(b, 0, wx.EXPAND|wx.ALL, 5)  
            s1 = wx.BoxSizer()  
            s1.Add(s, 0, wx.EXPAND, 0)  
            s1.Add(self.canvas, 1, wx.EXPAND|wx.ALL, 5)  
            self.SetSizer(s1)  
              
            self.Bind(wx.EVT_BUTTON, self.su_agg_q, agg_q)  
            self.Bind(wx.EVT_BUTTON, self.su_agg_c, agg_c)  
            self.Bind(wx.EVT_BUTTON, self.su_canc, canc)  
      
        def su_agg_q(self, evt): # aggiunge un quadrato  
            q = ogl.RectangleShape(50.0, 50.0)  
            self.aggiungi_forma(q)  
          
        def su_agg_c(self, evt):  # aggiunge un cerchio  
            c = ogl.CircleShape(50.0)  
            self.aggiungi_forma(c)  
              
        def su_canc(self, evt):  # se qualcosa e' selezionato, lo elimina  
            for shape in self.diag.GetShapeList():  
                if shape.Selected():   
                    shape.Select(False)  
                    self.canvas.RemoveShape(shape)  
            self.canvas.Refresh(False)  
          
        def aggiungi_forma(self, forma):  
            # una funzione di convenienza, solo per non ripetere due volte  
            # questo codice (in su_agg_q e su_agg_c)  
            forma.SetX(60.0)  
            forma.SetY(60.0)  
            self.canvas.AddShape(forma)  
            # ---- collego la forma appena creata al gestore degli eventi  
            # in questo modo  
            evthandler = MyEvtHandler()  
            evthandler.SetShape(forma)  
            evthandler.SetPreviousHandler(forma.GetEventHandler())  
            forma.SetEventHandler(evthandler)  
            # ------  
            forma.Show(True)  
            self.canvas.Refresh(False)  
      



class MyPanel1 ( wx.Panel ):
    
    def __init__( self, parent ):
        wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 800,600 ), style = wx.TAB_TRAVERSAL )
        
        sbSizer2 = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"label" ), wx.HORIZONTAL )
        
        self.m_splitter7 = wx.SplitterWindow( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SP_3D|wx.SP_3DBORDER|wx.SP_LIVE_UPDATE )
        self.m_splitter7.Bind( wx.EVT_IDLE, self.m_splitter7OnIdle )
        
        self.m_panel4 = wx.Panel( self.m_splitter7, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        bSizer13 = wx.BoxSizer( wx.VERTICAL )
        
        self.m_treeCtrl4 = wx.TreeCtrl( self.m_panel4, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TR_DEFAULT_STYLE )
        bSizer13.Add( self.m_treeCtrl4, 1, wx.ALL|wx.EXPAND, 5 )
        
        self.m_panel4.SetSizer( bSizer13 )
        self.m_panel4.Layout()
        bSizer13.Fit( self.m_panel4 )
        self.m_panel3 = wx.Panel( self.m_splitter7, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        bSizer6 = wx.BoxSizer( wx.VERTICAL )
        
        self.m_auinotebook2 = wx.aui.AuiNotebook( self.m_panel3, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.aui.AUI_NB_DEFAULT_STYLE )
        p=PannelloER(parent)
        self.m_auinotebook2.AddPage(p,"datamodel")
        bSizer6.Add( self.m_auinotebook2, 1, wx.EXPAND |wx.ALL, 5 )
        
        
        self.m_toolBar5 = wx.ToolBar( self.m_panel3, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TB_HORIZONTAL ) 
        self.m_toolBar5.AddLabelTool( wx.ID_ANY, u"tool", wx.Bitmap( u"D:\\workspace-eclipse\\esperimenti\\src\\grafica_wx\\new.bmp", wx.BITMAP_TYPE_ANY ), wx.NullBitmap, wx.ITEM_NORMAL, wx.EmptyString, wx.EmptyString ) 
        self.m_toolBar5.Realize()
        
        bSizer6.Add( self.m_toolBar5, 0, wx.EXPAND, 5 )
        
        self.m_panel3.SetSizer( bSizer6 )
        self.m_panel3.Layout()
        bSizer6.Fit( self.m_panel3 )
        self.m_splitter7.SplitVertically( self.m_panel4, self.m_panel3, 340 )
        sbSizer2.Add( self.m_splitter7, 1, wx.EXPAND, 5 )
        
        self.SetSizer( sbSizer2 )
        self.Layout()
    
    def __del__( self ):
        pass
    
    def m_splitter7OnIdle( self, event ):
        self.m_splitter7.SetSashPosition( 340 )
        self.m_splitter7.Unbind( wx.EVT_IDLE )
    





class RefactorExample(wx.MDIChildFrame):
    def __init__(self, *args, **kwargs):
        wx.MDIChildFrame.__init__(self, *args, **kwargs)
        statusBar = self.CreateStatusBar()
        panel = MyPanel1(self)
        panel.SetBackgroundColour("White")
        #self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        '''self.createMenuBar()
        self.createButtonBar(panel)
        self.createTextFields(panel)'''
        
        
class MDIFrame(wx.MDIParentFrame):
    def __init__(self):
        wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", 
                size=(800,600))
        menu = wx.Menu()
        menu.Append(5000, "&New Window")
        menu.Append(5001, "E&xit")
        menubar = wx.MenuBar()
        menubar.Append(menu, "&File")
        self.SetMenuBar(menubar)
        self.Bind(wx.EVT_MENU, self.OnNewWindow, id=5000)
        self.Bind(wx.EVT_MENU, self.OnExit, id=5001)

    def OnExit(self, evt):
        self.Close(True)

    def OnNewWindow(self, evt):
        win = RefactorExample(self, -1, "Child Window")
        win.Show(True)
        
if __name__ == '__main__':
    app = wx.PySimpleApp()
    ogl.OGLInitialize()
    frame = MDIFrame()
    frame.Show()
    app.MainLoop()






        
